import os
from datetime import datetime
import logging
import threading

import common.constants as const

class LogHelper():
     
    logging.basicConfig(level=logging.INFO, format='%(asctime)s %(filename)s %(threadName)s %(message)s',
                        datefmt='%Y%m%d %H:%M:%S', )
   
    @staticmethod
    def log_info(content: str,
                    filename=None):
        try:
            if not os.path.exists(const.DIC_PATH_LOG):
                os.makedirs(const.DIC_PATH_LOG)

            # # if self.console:
            # #     print(content)
            filename = filename if filename is not None else f"{datetime.now().strftime('%Y%m%d')}.log"

            file = os.path.join(const.DIC_PATH_LOG, filename)
            logging.info(content) 

            with open(file, 'a') as file_obj:
                file_obj.writelines(f"【{datetime.now().strftime('%m%d %H:%M:%S')}】<{threading.current_thread().name}>{content}\n")
        except Exception as e:
            print(e)

    # def log_life(self, content: str):
    #     if self.console:
    #         print(content)

    #     filename = f"{datetime.now().strftime('%Y%m')}_Life.log"
    #     self.log_file(content= f"【{datetime.now()}】   {content}", filename=filename)


    # def log_hq(self, content: str):
    #     if self.console:
    #         print(content)

    #     filename = f"{datetime.now().strftime('%Y%m')}_hq.log"
    #     self.log_file(content= f"【{datetime.now()}】   {content}", filename=filename)


    # def log_trade(self, content: str):
    #     if self.console:
    #         print(content)

    #     filename = f"{datetime.now().strftime('%Y%m')}_Trade.log"
    #     self.log_file(content=content, filename=filename)
            
    @staticmethod
    def log_error(content: str):
        filename = f"Error_{datetime.now().strftime('%Y%m%d')}.log"
        LogHelper.log_info(content=content, filename=filename)
        